package com.disapand.mybaby.api;


import com.disapand.mybaby.annotation.ApiIdempotent;
import com.disapand.mybaby.handle.ResultVO;
import com.disapand.mybaby.service.TokenService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author disapand
 */
@RestController
public class IndexController {

    private final TokenService tokenService;

    public IndexController(TokenService tokenService) {
        this.tokenService = tokenService;
    }

    @GetMapping("/")
    public ResultVO<String> index () {
        return ResultVO.ofSuccess("这是 v1 版本");
    }

    @GetMapping("echo")
    public ResultVO<String> echo () {
        return ResultVO.ofSuccess("回环信息");
    }

    @GetMapping("/getToken")
    public ResultVO<String> getToken () {
        String token = tokenService.createToken();
        return new ResultVO<>(token);
    }

    @GetMapping({"/testValidate/{name}", "/testValidate"})
    public ResultVO<String> validateTest (@PathVariable String name) {
        return ResultVO.ofSuccess(name);
    }

    @ApiIdempotent
    @GetMapping("/test")
    public String testIdempotent() {
        return "ceshi";
    }
}